'''
Created on Mar 20, 2013

@author: jason.richmond
'''

from SimPy.Simulation import *
from Globals import *
from Machine import Machine
from Job import EmailJob

class Arrival(Process):
    ArvRate = None
    
    def __init__(self):
        Process.__init__(self)
        
    def addJob(self, job):
        if(job.priorityServiceFlag):
            Machine.priorityQueue.append(job)
        else:
            Machine.Queue.append(job)
        
    def Run(self):
        while 1:
            #wait for arrival of next job
            yield hold,self,G.Rnd.expovariate(Arrival.ArvRate)
            J = EmailJob()
            self.addJob(J)
            
            if Machine.Idle != []:
                reactivate(Machine.Idle[0])